package com.yixun.qfbao.util;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ChannelStringUtils {
    public static List<String> getColumns(String content){
        List<String> list = new ArrayList<String>();
        Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
        Matcher m = p.matcher(content);
        while(m.find()){
            list.add(m.group().substring(1, m.group().length()-1));
        }
        return list;

    }

    /**
     * 替换map字段
     * @param content
     * @param map
     * @return
     */
    public static String replaceLabel(String content, Map<String,String> map){
        StringBuilder sb = new StringBuilder();
        for(Map.Entry<String,String> entry : map.entrySet()){
            if(content.contains("[" + entry.getKey()+ "]")){
               content = content.replace("[" + entry.getKey()+ "]", StringUtils.defaultIfBlank(entry.getValue(), ""));
            }
        }
        return content.replace("\ufeff","");
    }
}
